package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.ShopKeepTaskEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AdvancedTaskAdapter extends RecyclerView.Adapter<AdvancedTaskAdapter.AdvancedTaskViewHolder> {



    private Context context;

    private List<ShopKeepTaskEntity> taskEntityList;

    public AdvancedTaskAdapter(Context context, List<ShopKeepTaskEntity> taskEntityList) {
        this.context = context;
        this.taskEntityList = taskEntityList;
    }


    @NonNull
    @Override
    public AdvancedTaskViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new AdvancedTaskViewHolder(LayoutInflater.from(context).inflate(R.layout.advanced_tast_view_holder, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull AdvancedTaskViewHolder advancedTaskViewHolder, int i) {
       if (i % 3 == 0) {
            advancedTaskViewHolder.viewMargin.setVisibility(View.VISIBLE);
        } else {
            advancedTaskViewHolder.viewMargin.setVisibility(View.GONE);
        }

        advancedTaskViewHolder.tvTask.setText(taskEntityList.get(i).taskName);
        if(taskEntityList.get(i).taskStatus.equals("0")){
            advancedTaskViewHolder.linearLock.setVisibility(View.VISIBLE);
            advancedTaskViewHolder.linearFinished.setVisibility(View.GONE);
            advancedTaskViewHolder.linearUnfinished.setVisibility(View.GONE);
            advancedTaskViewHolder.linearLock.setEnabled(false);
            advancedTaskViewHolder.itemView.setEnabled(false);
        }else if(taskEntityList.get(i).taskStatus.equals("1")){
            advancedTaskViewHolder.linearLock.setVisibility(View.GONE);
            advancedTaskViewHolder.linearFinished.setVisibility(View.GONE);
            advancedTaskViewHolder.linearUnfinished.setVisibility(View.VISIBLE);
            advancedTaskViewHolder.linearLock.setEnabled(true);
            advancedTaskViewHolder.itemView.setEnabled(true);
        }else {
            advancedTaskViewHolder.linearLock.setVisibility(View.GONE);
            advancedTaskViewHolder.linearFinished.setVisibility(View.VISIBLE);
            advancedTaskViewHolder.linearUnfinished.setVisibility(View.GONE);
            advancedTaskViewHolder.linearLock.setEnabled(true);
            advancedTaskViewHolder.itemView.setEnabled(false);
        }

        advancedTaskViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UpgradeShopKeeperActivity.class);
                context.startActivity(intent);
            }
        });



    }

    @Override
    public int getItemCount() {
        return taskEntityList.size();
    }

    public class AdvancedTaskViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_task)
        TextView tvTask;
        @BindView(R.id.view_margin)
        View viewMargin;
        @BindView(R.id.linear_unfinished)
        LinearLayout linearUnfinished;
        @BindView(R.id.linear_finished)
        LinearLayout linearFinished;
        @BindView(R.id.linear_lock)
        LinearLayout linearLock;

        public View itemView;

        public AdvancedTaskViewHolder(@NonNull View itemView) {
            super(itemView);
            this.itemView = itemView;
            ButterKnife.bind(this, itemView);
        }
    }
}
